package com.warrantyhotel.android.adapter;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.warrantyhotel.android.R;
import com.warrantyhotel.android.util.JSONParser;

public class CreditsAdapter extends ArrayAdapter<String> {

	private Context context;
	private static SharedPreferences prefs;
	private String remainingCredits;


	public CreditsAdapter(Context context, int textViewResourceId, String[] items) {
		super(context, textViewResourceId, items);
		this.context = context;
		prefs = PreferenceManager.getDefaultSharedPreferences(context);
		remainingCredits = prefs.getString(JSONParser.REMAINING_CREDITS, "0");
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.get_credit_item, null);
		}
		TextView tt = (TextView) v.findViewById(R.id.credit_title);
		TextView bt = (TextView) v.findViewById(R.id.credit_value);

		switch (position) {
//		case 0:
//			tt.setText(context.getString(R.string.get_free_points));
//			bt.setText(context.getString(R.string.get_points_for_free));
//			break;
		case 0:
			tt.setText(context.getString(R.string.buy_points));
			bt.setText(context.getString(R.string.buy_points_via));
			break;
		case 1:
			tt.setText(context.getString(R.string.your_points));
			bt.setText(remainingCredits);
			break;
		// case 3:
		// tt.setText("Your Uploads:");
		// bt.setText(remainingUploads);
		// break;
		default:
			break;
		}
		return v;
	}

}
